<%@ page import="java.sql.Connection" %>
<%@ page import="java.sql.Statement" %>
<%@ page import="java.sql.DriverManager" %>
<%@ page import="java.sql.PreparedStatement" %><%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2025/4/27
  Time: 20:55
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
</head>
<body>
<%
    String stuNo = request.getParameter("stu_no");//学号

    /**
     * 以下代码为连接数据库代码
     */
    String dbname = "goods";//数据库名称
    String username = "root";//数据库用户名
    String password = "1234";//数据库密码
    String url =  "jdbc:mysql://localhost:3306/" +dbname;
//    Class.forName("com.mysql.jdbc.Driver");//mysql 5.7一下的版本
    Class.forName("com.mysql.cj.jdbc.Driver");//mysql 8.0
    Connection connection = DriverManager.getConnection(url,username,password);
    Statement statement = connection.createStatement();

    String sql = "delete from student where stu_no=?";
    PreparedStatement preparedStatement = connection.prepareStatement(sql);
    preparedStatement.setString(1,stuNo);//数字1表示上方数据库语句中第一个问号要替换的值 stuName


    int resulet = preparedStatement.executeUpdate();
    System.out.println(resulet);
    if(resulet>0){//删除成功
        response.sendRedirect("search.jsp");//回到搜索页面
    }

%>
</body>
</html>
